package com.far.game.xiuzhen.gm.web.api.admin;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.far.game.xiuzhen.common.database.entity.DictCharProp;
import com.far.game.xiuzhen.common.database.entity.Servers;
import com.far.game.xiuzhen.common.database.entity.Skills;
import com.far.game.xiuzhen.common.database.entity.User;

import com.far.game.xiuzhen.gm.web.BaseController;
import com.far.game.xiuzhen.service.IDictCharPropService;
import com.far.tools.bean.BeanUtil;
import com.far.tools.net.http.ReqParamWrapper;
import com.far.tools.net.http.transfer.ResultData;
import com.mysql.fabric.FabricConnection;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.lucene.search.similarities.Lambda;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mike
 * @since 2022-07-15
 */
//针对这个 Controller 类的描述
@Api(tags = "数据字典层")
@RestController
@RequestMapping(value = "/api/admin/dict/data")
public class DictDataController extends BaseController {


    @Autowired
    @Qualifier("dictCharPropServiceImpl")
    private IDictCharPropService iDictCharPropService;


    @ApiOperation(value = "新增人物属性", notes = "新增人物属性信息")
    @PostMapping(value = "character-properties-add")
    private ResultData<String> characterPropertiesAdd(@RequestBody DictCharProp dictCharProp) {
        dictCharProp.setCreateBy(this.getVisitor().getUserName());
        dictCharProp.setUpdateBy(this.getVisitor().getUserName());
        if (iDictCharPropService.save(dictCharProp)) {
            return ResultData.ok("添加成功");
        }
        return ResultData.error("添加失败");
    }

    @ApiOperation(value = "人物属性更新", notes = "人物属性信息更新")
    @PostMapping(value = "character-properties-update")
    private ResultData<String> characterPropertiesUpdate(@RequestBody DictCharProp dictCharProp) {

        dictCharProp.setUpdateBy(this.getVisitor().getUserName());
        if (iDictCharPropService.updateById(dictCharProp)) {
            return ResultData.ok("更新成功");
        }
        return ResultData.error("更新失败");
    }


    @NotNull(message = "数据不能为空")
    @ApiOperation(value = "人物属性删除", notes = "人物属性信息删除")
    @ApiImplicitParam(name = "tid", value = "ID", required = true, paramType = "query", dataType = "Integer")
    @GetMapping(value = "character-properties-remove")
    private ResultData<String> characterPropertiesRemove(@RequestParam("tid") Integer tid) {
        if (iDictCharPropService.removeById(tid)) {
            return ResultData.ok("删除成功");
        }
        return ResultData.error("删除失败");
    }

    @ApiOperation(value = "人物属性查询", notes = "ReqParamWrapper")
    @PostMapping(value = "query")
    private ResultData<IPage<DictCharProp>> Query(@RequestBody ReqParamWrapper<DictCharProp, String> reqParamWrapper) {
        IPage<DictCharProp> iPage = reqParamWrapper.pageLists(iDictCharPropService);
        if (iPage.getRecords().size() == 0) {
            return ResultData.error("暂无数据");
        }
        return ResultData.ok(iPage);

    }

}